package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.PartyStudyResource;
import com.ruoyi.system.mapper.PartyStudyResourceMapper;
import com.ruoyi.system.service.IPartyStudyResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 党建学习资源Service业务层处理
 */
@Service
public class PartyStudyResourceServiceImpl implements IPartyStudyResourceService {

    @Autowired
    private PartyStudyResourceMapper partyStudyResourceMapper;

    @Override
    public PartyStudyResource selectPartyStudyResourceById(Long id) {
        return partyStudyResourceMapper.selectPartyStudyResourceById(id);
    }

    @Override
    public List<PartyStudyResource> selectPartyStudyResourceList(PartyStudyResource resource) {
        return partyStudyResourceMapper.selectPartyStudyResourceList(resource);
    }

    @Override
    public int insertPartyStudyResource(PartyStudyResource resource) {
        if (resource.getSortOrder() == null) {
            resource.setSortOrder(0);
        }
        if (StringUtils.isEmpty(resource.getStatus())) {
            resource.setStatus("0");
        }
        if (resource.getPublishTime() == null && "0".equals(resource.getStatus())) {
            resource.setPublishTime(DateUtils.getNowDate());
        }
        resource.setCreateTime(DateUtils.getNowDate());
        return partyStudyResourceMapper.insertPartyStudyResource(resource);
    }

    @Override
    public int updatePartyStudyResource(PartyStudyResource resource) {
        if (resource.getPublishTime() == null && "0".equals(resource.getStatus())) {
            resource.setPublishTime(DateUtils.getNowDate());
        }
        resource.setUpdateTime(DateUtils.getNowDate());
        return partyStudyResourceMapper.updatePartyStudyResource(resource);
    }

    @Override
    public int deletePartyStudyResourceByIds(Long[] ids) {
        return partyStudyResourceMapper.deletePartyStudyResourceByIds(ids);
    }

    @Override
    public int deletePartyStudyResourceById(Long id) {
        return partyStudyResourceMapper.deletePartyStudyResourceById(id);
    }
}

